package com.xmy.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.erp.entity.Quarter;
import com.xmy.erp.mapper.QuarterMapper;
import com.xmy.erp.service.IQuarterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 每年季度 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2023-09-09
 */
@Service
public class QuarterServiceImpl extends ServiceImpl<QuarterMapper, Quarter> implements IQuarterService {

    @Autowired
    QuarterMapper quarterMapper;

    public Quarter getNowQuarter(){
        LocalDate nowDate = LocalDate.now();
        QueryWrapper<Quarter> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("start_date",nowDate);
        queryWrapper.ge("end_date",nowDate);
        queryWrapper.last("limit 1");
        Quarter quarter = quarterMapper.selectOne(queryWrapper);
        return quarter;
    }
}
